﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using NetBay.Core.Log;
using NetBay.Core.DataAccess;
using Rio.Framework.RioManager;
using System.Data.OracleClient;

namespace Rio.Manager.DataAccess
{
    public class DA_NumerizationOperatorByDate
    {
        #region Enums

        public enum DbFunction
        {
            [DescriptionAttribute("")]
            None,
            [DescriptionAttribute("P_REPORT_MASS_IMPORT_BY_DATE")]
            GetReportMassImportByOperatorByDate,
        }

        #endregion

        /// <summary>
        /// Get numerization resum by operator by date
        /// </summary>
        /// <param name="StartDate">Starting Date</param>
        /// <param name="EndDate">endingDate</param>
        /// <returns></returns>
        public static IDataReader GetNumerizationReportByOperatorByDate(DateTime StartDate, DateTime EndDate)
        {
            try
            {
                LogManager.Instance().LogDebug("(p_dStartDate<" + StartDate.ToString() + ">)(p_dEndDate<" + EndDate.ToString() + ">)");
                var db = DbHelper.DataBase;

                var l_bOutPutParameter = false;
                var l_sPackageName = string.Empty;
                switch (SettingsManager.cStoreSettings.Parameter_EngineDataBase)
                {
                    case "Oracle":
                        l_bOutPutParameter = true;
                        l_sPackageName = SettingsManager.cStoreSettings.Parameter_OraclePackage;
                        break;
                }

                var dbCommand = db.GetStoredProcCommand(l_sPackageName + DbFunction.GetReportMassImportByOperatorByDate.szGetDescription());
                db.AddInParameter(dbCommand, "p_dStartDate", DbType.String, StartDate.ToShortDateString());
                db.AddInParameter(dbCommand, "p_dEndDate", DbType.String, EndDate.ToShortDateString());

                if (l_bOutPutParameter)
                {
                    var l_oOracleOutputParameter = new OracleParameter("O_Results", OracleType.Cursor);
                    l_oOracleOutputParameter.Direction = ParameterDirection.Output;
                    dbCommand.Parameters.Add(l_oOracleOutputParameter);
                }

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                LogManager.Instance().LogError("DA_NumerizationOperatorByDate --> GetNumerizationReportByOperatorByDate exception[" + ex.Message + "]");
                return null;
            }
        }
    }
}
